﻿using Minio;
using Minio.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using YL.Utils.Pub;

namespace YL.Utils.Files
{
    public static class MinioUtil
    {
        public static async Task<string> GetMinioObject(string bucketName, string objectName, int expired = 60 * 60 * 24)
        {
            var minioClient = new MinioClient(
                PubMinio.EndPoint,
                PubMinio.AccessKey,
                PubMinio.SecretKey
                ).WithSSL();
            try
            {
                string url = await minioClient.PresignedGetObjectAsync(bucketName, objectName, expired);
                return url;
            }
            catch (MinioException e) 
            {
                return e.Message;
            }
        }
    }
}
